package com.acwing.partition12;

import java.io.*;
import java.util.*;

/**
 * @author `RKC`
 * @date 2022/1/23 16:36
 */
public class AC1171距离_tarjan {

    private static final int N = (int) (1e4 + 10), M = N * 2, D = (int) (Math.log(N) / Math.log(2));
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    private static int[] dist = new int[M], parent = new int[N], res = new int[M], st = new int[N];

    private static int n = 0, idx = 0;
    private static Map<Integer, List<int[]>> question = new HashMap<>(N);

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);
        for (int i = 0; i < N; i++) {
            head[i] = -1;
            parent[i] = i;
        }
        for (int i = 0; i < n - 1; i++) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
            add(u, v, w);
            add(v, u, w);
        }
        for (int i = 0; i < k; i++) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]);
            if (u != v) {
                List<int[]> que = question.getOrDefault(u, new ArrayList<>());
                que.add(new int[]{v, i});
                question.put(u, que);
                que = question.getOrDefault(v, new ArrayList<>());
                que.add(new int[]{u, i});
                question.put(v, que);
            }
        }
        dfs(1, -1);
        tarjan(1);
        for (int i = 0; i < k; i++) writer.write(res[i] + "\n");
        writer.flush();
    }

    private static void tarjan(int u) {
        st[u] = 1;
        for (int i = head[u]; i != -1; i = next[i]) {
            int v = element[i];
            if (st[v] == 0) {
                tarjan(v);
                parent[v] = u;
            }
        }
        //查找是否有询问和u节点有关的
        List<int[]> que = question.getOrDefault(u, null);
        if (que == null) {
            st[u] = 2;
            return;
        }
        for (int[] item : que) {
            int v = item[0], id = item[1];
            //只有已经访问过的节点的状态，并查集的find才会有效
            if (st[v] == 2) {
                int p = find(v);
                res[id] = dist[u] + dist[v] - 2 * dist[p];
            }
        }
        st[u] = 2;
    }

    private static void dfs(int u, int last) {
        for (int i = head[u]; i != -1; i = next[i]) {
            int v = element[i];
            if (v == last) continue;
            dist[v] = dist[u] + weight[i];
            dfs(v, u);
        }
    }

    private static int find(int x) {
        if (x != parent[x]) parent[x] = find(parent[x]);
        return parent[x];
    }

    private static void add(int u, int v, int w) {
        element[idx] = v;
        next[idx] = head[u];
        head[u] = idx;
        weight[idx++] = w;
    }
}
